﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TdocumentsDB : BaseDB
    {
        public TdocumentsDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TdocumentsDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tDocuments (Filename,Filepath,Pubdate,Usersid,Note,OrgID) VALUES ('", StringUtils.ToSQL(detail.Filename), "','", StringUtils.ToSQL(detail.Filepath), "','", detail.Pubdate, "',", detail.Usersid, ",'", StringUtils.ToSQL(detail.Note), "',"+ detail.OrgID +")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tDocuments where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TdocumentsDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "UPDATE tDocuments set Filename='", StringUtils.ToSQL(detail.Filename), "',Filepath='", StringUtils.ToSQL(detail.Filepath), "',Pubdate='", detail.Pubdate, "',Usersid=", detail.Usersid, ",Note='", StringUtils.ToSQL(detail.Note), "',OrgID="+ detail.OrgID +" where (Sid=", detail.Sid, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TdocumentsDT Get(int Sid)
        {
            TdocumentsDT sdt = new TdocumentsDT();
            try
            {
                try
                {
                    string strSql = "select * from tDocuments where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        sdt.Sid = Convert.ToInt32(row["Sid"]);
                        sdt.Filename = Convert.ToString(row["Filename"]);
                        sdt.Filepath = Convert.ToString(row["Filepath"]);
                        sdt.Pubdate = Convert.ToDateTime(row["Pubdate"]);
                        sdt.Usersid = Convert.ToInt32(row["Usersid"]);
                        sdt.Note = Convert.ToString(row["Note"]);
                        sdt.OrgID = Convert.ToInt32(row["OrgID"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return sdt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tDocuments";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

